package com.ruoyi.web.controller.disasterAssessment;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.disasterassessment.domain.AlarmWarnPredictionHistory;
import com.ruoyi.disasterassessment.dto.AlarmWarnPredictionHistoryDto;
import com.ruoyi.disasterassessment.service.IAlarmWarnPredictionHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 预警预测模拟历史数据Controller
 * 
 * @author hcc
 * @date 2023-12-20
 */
@RestController
@RequestMapping("/disasterassessment/history")
public class AlarmWarnPredictionHistoryController extends BaseController
{
    @Autowired
    private IAlarmWarnPredictionHistoryService alarmWarnPredictionHistoryService;

    /**
     * 查询预警预测模拟历史数据列表
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:history:list')")
    @GetMapping("/list")
    public TableDataInfo list(AlarmWarnPredictionHistory alarmWarnPredictionHistory)
    {
        startPage();
        List<AlarmWarnPredictionHistory> list = alarmWarnPredictionHistoryService.selectAlarmWarnPredictionHistoryList(alarmWarnPredictionHistory);
        return getDataTable(list);
    }

    /**
     * 导出预警预测模拟历史数据列表
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:history:export')")
    @Log(title = "预警预测模拟历史数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AlarmWarnPredictionHistory alarmWarnPredictionHistory)
    {
        List<AlarmWarnPredictionHistory> list = alarmWarnPredictionHistoryService.selectAlarmWarnPredictionHistoryList(alarmWarnPredictionHistory);
        ExcelUtil<AlarmWarnPredictionHistory> util = new ExcelUtil<AlarmWarnPredictionHistory>(AlarmWarnPredictionHistory.class);
        util.exportExcel(response, list, "预警预测模拟历史数据数据");
    }

    /**
     * 获取预警预测模拟历史数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:history:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(alarmWarnPredictionHistoryService.selectAlarmWarnPredictionHistoryById(id));
    }

    /**
     * 新增预警预测模拟历史数据
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:history:add')")
    @Log(title = "预警预测模拟历史数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AlarmWarnPredictionHistory alarmWarnPredictionHistory)
    {
        return toAjax(alarmWarnPredictionHistoryService.insertAlarmWarnPredictionHistory(alarmWarnPredictionHistory));
    }

    /**
     * 修改预警预测模拟历史数据
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:history:edit')")
    @Log(title = "预警预测模拟历史数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AlarmWarnPredictionHistory alarmWarnPredictionHistory)
    {
        return toAjax(alarmWarnPredictionHistoryService.updateAlarmWarnPredictionHistory(alarmWarnPredictionHistory));
    }

    /**
     * 删除预警预测模拟历史数据
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:history:remove')")
    @Log(title = "预警预测模拟历史数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(alarmWarnPredictionHistoryService.deleteAlarmWarnPredictionHistoryByIds(ids));
    }
    /**
     * 通过modelId获取预警预测模拟历史数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('disasterassessment:history:query')")
    @GetMapping("/getAlarmWarnPredictionHistoryByModelId/{id}")
    public AjaxResult getAlarmWarnPredictionHistoryByModelId(@PathVariable("id") String modelId) {
        List<AlarmWarnPredictionHistoryDto> alarmWarnPredictionHistoryDtoList = alarmWarnPredictionHistoryService.getAlarmWarnPredictionHistoryByModelId(modelId);
        return success(alarmWarnPredictionHistoryDtoList);
    }
}
